<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib prefix="s" uri="/struts-tags"%> 
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<sx:head cache="false" parseContent="true"/>
<link rel="stylesheet" type="text/css" href="css/reserve.css" />

<script language="javascript" type="text/javascript" src="js/datevalidate.js"></script>
<script language="javascript" type="text/javascript" src="js/CommonReserve.js"></script>
<script language="javascript" type="text/javascript" src="js/AjaxHandlerUtil.js"></script>
<script language="javascript" type="text/javascript" src="js/NumberFormat154.js"></script>

<script language="javascript">      
dojo.event.topic.subscribe("/beforeAddCustomer", function(event, widget){
    try{
		var title 		= document.getElementById("title");
		var firstName 	= document.getElementById("firstName");
		var lastName 	= document.getElementById("lastName");
		
        if(title.value == ""){
			alert("Please input title");
			title.focus();
			event.cancel = true;
		}else if(firstName.value == ""){
			alert("Please input firstName");
			firstName.focus();
			event.cancel = true;
		}else if(lastName.value == ""){
			alert("Please input lastName");
			lastName.focus();
			event.cancel = true;
       	}else{
       		if(!confirm("Do you want to save?")){
       			event.cancel = true;
       		}
       	}
    }catch(err ) {
         alert("Javascript error in this reserve info page beforeAddCustomer main function() [Error: " + err.message + "]");
         event.cancel = true;
    }
});

window.focus();
if (!window.opener)
	window.document.write();

var openerObj = window.opener;
function refreshReserveDetail(){
	var opennerForm 						= openerObj.frmReserveDetail;	
	
	var flagSave							= document.getElementById("flagSave").value;
	var customerId							= document.getElementById("customerId").value;
	if(customerId != '' && parseInt(customerId) > 0 && flagSave != '' && flagSave == 'Y'){
		opennerForm.customerId.value		= customerId;
		openerObj.refreshReserveDetail();	
		window.close();
	}
}
</script> 
    
<sx:div id="customerDIV" loadingText="Loading..." showLoadingText="true"
    parseContent="true" separateScripts="true" executeScripts="true" refreshOnShow="true" cssClass="yui-skin-sam"  >
   
    <s:form id="frmCustomer" name="frmCustomer" method="post" theme="simple" >    
  
        <!--subDetail-->
		<div style="height:450px; width:600px; padding-top: 5px; overflow:auto;">                        	
        <table cellpadding="0" cellspacing="0" border="0" width="100%" align="center" >     
            <tr> 
                <td valign="top" width="100%" >           
                    
                    <table cellpadding="0" cellspacing="0" border="0" width="98%" align="center" >   
                        <tr><td height="5"></td></tr>
                        <tr> 
                            <td >
                                <s:actionerror />
                                <s:actionmessage cssStyle="font: bolder;color: blue;"  />
                            </td>
                        </tr>
                        <tr><td height="10"></td></tr>
                        <!--blue space-->
                        <tr>
							<td width="100px"><s:label key="reserve.room.cust.custnumber" /></td>
							<td colspan="3">
							   	<s:textfield id="customerId" name="customerVO.customerId" readonly="true" cssClass="iDL"/>
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.title" /><font color="red">*</font></td>
							<td colspan="3">
								<s:select id="title" name="customerVO.title" list="%{titleList}" listKey="key" listValue="value"/>			                        									   	
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.firstname" /><font color="red">*</font></td>
							<td colspan="3">
							   	<s:textfield id="firstName" name="customerVO.firstName" cssClass="iNL" size="50" maxlength="250"/>
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.lastname" /><font color="red">*</font></td>
							<td colspan="3">
							   	<s:textfield id="lastName" name="customerVO.lastName" cssClass="iNL" size="50" maxlength="250"/>
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.gender" /></td>
							<td colspan="3">
								<s:select id="gender" name="customerVO.gender" list="%{genderList}" listKey="value" listValue="value" headerKey="" headerValue=""/>			                        									   	
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.address" /></td>
							<td colspan="3">
							   	<s:textfield id="address" name="customerVO.address" cssClass="iNL" size="70" maxlength="250"/>
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.district" /></td>
							<td colspan="3">
							   	<s:textfield id="district" name="customerVO.district" cssClass="iNL" size="70" maxlength="250"/>
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.amphur" /></td>
							<td colspan="3">
							   	<s:textfield id="amphur" name="customerVO.amphur" cssClass="iNL" size="70" maxlength="250"/>
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.province" /></td>
							<td>
								<s:select id="province" name="customerVO.province" list="%{provinceList}" listKey="key" listValue="value"  headerKey="" headerValue=""/>			                        									   	
							</td>
							<td><s:label key="reserve.room.cust.zipcode" /></td>
							<td>
							   	<s:textfield id="zipcode" name="customerVO.zipcode" cssClass="iNL" size="10" maxlength="5"/>
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.nationality" /></td>
							<td colspan="3">
								<s:select id="nationality" name="customerVO.nationality" list="%{nationalityList}" listKey="value" listValue="value"  headerKey="" headerValue=""/>			                        									   	
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.telephone" /></td>
							<td colspan="3">
							   	<s:textfield id="telephone" name="customerVO.telephone" cssClass="iNL" maxlength="30"/>
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.mobile" /></td>
							<td colspan="3">
							   	<s:textfield id="mobile" name="customerVO.mobile" cssClass="iNL" maxlength="30"/>
							</td>
                        </tr>
                        <tr>
							<td><s:label key="reserve.room.cust.email" /></td>
							<td colspan="3">
							   	<s:textfield id="email" name="customerVO.email" cssClass="iNL" maxlength="30"/>
							</td>
                        </tr>
                        <tr><td colspan="4"><hr></td></tr>						
                        <tr>
                        	<td colspan="4" align="center">
	                        	<s:hidden name="flagSave" id="flagSave"/>
                        		<s:if test="customerVO.customerId > 0">
								<sx:submit key="reserve.room.cust.button.ok" indicator="customerIndicator" id="btnSaveCustomer" 
								   targets="customerDIV" href="reserveDetail_editCustomer.action" beforeNotifyTopics="/beforeAddCustomer">
								</sx:submit>
                        		</s:if>
                        		<s:else>
									<sx:submit key="reserve.room.cust.button.ok" indicator="customerIndicator" id="btnSaveCustomer" 
									   targets="customerDIV" href="reserveDetail_addCustomer.action" beforeNotifyTopics="/beforeAddCustomer">
									</sx:submit>
                        		</s:else>
								<input type="button" value="<s:text name="reserve.room.cust.button.cancel" />" onclick="window.close()" class="button" />
								<img id="customerIndicator" src="${pageContext.request.contextPath}/images/indicator.gif" alt="Loading..." style="display:none"/>
                        	</td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        </div>
    </s:form>
<s:url id="refreshReserveInfoRoomURL" value="refreshReserveInfoRoom.action?" />
<sx:div id="refreshReserveInfoRoomDIV" autoStart="false" parseContent="true" executeScripts="true"
        separateScripts="true" showLoadingText="true"
        href="%{refreshReserveInfoRoomURL}" refreshOnShow="true"></sx:div>        
        
</sx:div>
